<?php

declare(strict_types=1);

namespace So\App\Request\Backend;

use So\App\Model\Backend\AuthRule;
use So\Validation;
use Hyperf\Validation\Rule;

class AuthRuleRequest extends Validation
{
    public $scene = [
        'create' => ['type', 'pid', 'name', 'title'],
        'delete' => ['ids'],
    ];

    public function rules(): array
    {
        return [
            'name' => [
                'required',
                Rule::unique('auth_rule')->ignore(\input('id'))
            ],
            'type' => 'required',
            'pid' => 'required',
            'id' => 'required|integer',
            'title' => 'required',
            'hidden' => '',
            'hiddenBreadcrumb' => '',
            'icon' => '',
            'sort' => '',
            'path' => 'required',
            'redirect' => '',
            'ids' => "array|required_without_all:id,pid,name,path",
        ];
    }

    public function messages(): array
    {
        return [
            'name.required' => '请填写名称',
            'name.unique' => '名称已存在',
            'type.required' => '请选择菜单类型',
            'pid.required' => '请选择上级',
            'id.required' => '请传入ID',
            'id.integer' => 'ID只能为整数',
            'title.required' => '请填写标题',
            'path.required' => '请填写路由地址',
            'ids.required_without_all' => '未传入删除项',
        ];
    }
}